package com.hyh.prize.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyh.prize.service.GgkService;


import com.hyh.prize.entity.TabGgcardInfo;
import com.lww.springcloudapi.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/ggk/")
@Api(tags = "刮刮卡信息管理")
public class GgkController {
    @Resource
    private GgkService ggkService;

    @GetMapping("get/{id}")
    @ApiOperation("根据刮刮卡id,查询刮刮卡信息")
    public Result getGgkById(@PathVariable long id){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("CARDNO",id);
        TabGgcardInfo byId = ggkService.getOne(queryWrapper);
        return Result.ok(byId);
    }

    @PostMapping("list/{current}/{limit}")
    @ApiOperation("查询所有刮刮卡信息")
    public Result getGgkList(@PathVariable Long current,@PathVariable Long limit,@RequestBody TabGgcardInfo tabGgcardInfo){
        Page page=new Page(current,limit);
        QueryWrapper queryWrapper=new QueryWrapper();
        //查询中奖的刮刮卡
        queryWrapper.ne("PRIZELEVEL","6");

        if(tabGgcardInfo.getPrizelevel()!=null && tabGgcardInfo.getPrizelevel()>0){
            queryWrapper.eq("PRIZELEVEL",tabGgcardInfo.getPrizelevel());
        }
        if(tabGgcardInfo.getState()!=null && tabGgcardInfo.getState().equals("")){
            queryWrapper.eq("STATEDATE",tabGgcardInfo.getState());
        }
        if(tabGgcardInfo.getAcptsiteid() != null && tabGgcardInfo.getAcptsiteid().equals("")){
            queryWrapper.eq("ACPTSITEID",tabGgcardInfo.getAcptsiteid());
        }
        Page ggkPage = ggkService.page(page, queryWrapper);
        return Result.ok(ggkPage);
    }

    @PostMapping("updateGgk")
    @ApiOperation("根据id,修改刮刮卡信息")
    public Result updateGgk(@RequestBody TabGgcardInfo tabGgcardInfo){

      Boolean b=ggkService.seveGgk(tabGgcardInfo);
       if(b){
           return Result.ok();
       }
       return Result.fail();

    }

    @DeleteMapping("del/{id}")
    @ApiOperation("根据刮刮卡id，删除刮刮卡")
    public Result delById(Long id){
        ggkService.removeById(id);
        return Result.ok();
    }
}
